﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RabbitMQ.Client;

namespace NewTask
{
    public class Program
    {
        public static void Main(string[] args)
        {
            const string queueName = "hello_agian";
            Console.WriteLine("send runing");
            string message = getMessage(args);
            Console.WriteLine("message : {0}", message);
            var body = Encoding.UTF8.GetBytes(message);

            ConnectionFactory factory = new ConnectionFactory();
            factory.HostName = "192.168.64.130";
            factory.UserName = "root";
            factory.Password = "root";
            factory.Port = 5672;

            using (var conn=factory.CreateConnection())
            {
                using (var channel=conn.CreateModel())
                {
                    channel.QueueDeclare(queueName, false, false, false, null);
                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;
                    channel.BasicPublish("", "task_queue", properties, body);
                }
            }
            Console.WriteLine("send ending");

            //Console.ReadLine();
        }

        private static string getMessage(string [] args)
        {
            return (args.Length > 0 ? string.Join(" ", args) : " hello again ! ");
        }
    }
}
